package com.yq.cp.controller.basics;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.yq.cp.config.UserThreadLocal;
import com.yq.cp.entity.basics.InspectionItemManagement;
import com.yq.cp.entity.common.ApiResult;
import com.yq.cp.entity.common.PageVo;
import com.yq.cp.service.basics.InspectionItemManagementService;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.Objects;

/**
 * <p>
 * 巡检项管理 前端控制器
 * </p>
 *
 * @author shenyuqing
 * @since 2024-08-27
 */
@RestController
@RequestMapping("/inspectionItemManagement")
public class InspectionItemManagementController {
    @Resource
    InspectionItemManagementService inspectionItemManagementService;

    /**
     * 添加编辑
     * @param inspectionItemManagement
     * @return
     */
    @PostMapping("add")
    public ApiResult add(@RequestBody InspectionItemManagement inspectionItemManagement){
        if (Objects.isNull(inspectionItemManagement.getId()))
            inspectionItemManagement.setCreateName(UserThreadLocal.get().getUsername());
        inspectionItemManagementService.saveOrUpdate(inspectionItemManagement);
        return ApiResult.success();
    }

    /**
     * 删除
     * @param inspectionItemManagement
     * @return
     */
    @PostMapping("remove")
    public ApiResult remove(@RequestBody InspectionItemManagement inspectionItemManagement){
        inspectionItemManagementService.removeById(inspectionItemManagement);
        return ApiResult.success();
    }

    /**
     * 列表
     * @param vo
     * @return
     */
    @PostMapping("list")
    public ApiResult list(@RequestBody PageVo vo){
        Page<InspectionItemManagement> page = new Page<>(vo.getPage(), vo.getSize());
        QueryWrapper<InspectionItemManagement> wrapper = new QueryWrapper<>();
        if (!Objects.isNull(vo.getLike())&&!"".equals(vo.getLike()))
            wrapper.like("name",vo.getLike());
        wrapper.eq("site_id",vo.getSiteId());
        page = inspectionItemManagementService.page(page,wrapper);
        return ApiResult.success(page);
    }


}

